//
//  LzwNewTwoController.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/2.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwNewTwoController.h"
#import "UMSocial.h"

@interface LzwNewTwoController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@end

@implementation LzwNewTwoController

-(void)dealloc{
    [_activityIndicator release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = self.modleN.title;
    
    UIImage * LandRightBar = [UIImage imageNamed:@"return.png"];
    LandRightBar = [LandRightBar imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:LandRightBar style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction:)];
    //设置分享按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"100.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonAction:)];
    
    [self.navigationItem.rightBarButtonItem setImageInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    
    
    
    
    
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
    
    [self.webView setUserInteractionEnabled:YES];
    [self.webView setBackgroundColor:[UIColor clearColor]];
    [self.webView setOpaque:NO];//使网页透明

    [self.view addSubview:self.webView];
    NSString *string = self.modleN.id;
    
    NSString *string1 = @"http://m.ibantang.com/topic/detail/";
    
    NSString *str = [string1 stringByAppendingString:string];
    
    
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:str]];
    [self.view addSubview: self.webView];
    [self.webView loadRequest:request];
    
    [self.webView setDelegate:self];

//
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    [view setTag:103];
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.1];
    [self.view addSubview:view];
    
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [self.activityIndicator setCenter:view.center];
    [self.activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [view addSubview:self.activityIndicator];
    [self.view addSubview:self.webView];
    [view release];
    [_webView release];
    
}

- (void)leftButtonAction: (UIBarButtonItem *)na{
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
    
    
    [self.activityIndicator startAnimating];

   
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
    [self.activityIndicator stopAnimating];
    UIView *view = (UIView *)[self.view viewWithTag:103];
    [view removeFromSuperview];
    
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"亲 网络不给力" preferredStyle:UIAlertControllerStyleAlert];
    
    
    [self presentViewController:alert animated:YES completion:^{

        
    }];
    UIAlertAction *ale = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }];
    
    [alert addAction:ale];
    
    
}
//分享按钮
- (void)shareButtonAction:(UIBarButtonItem *)buto{
    
    //注意：分享到微信好友、微信朋友圈、微信收藏、QQ空间、QQ好友、来往好友、来往朋友圈、易信好友、易信朋友圈、Facebook、Twitter、Instagram等平台需要参考各自的集成方法
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"56911ce367e58e117a002ed8"
                                      shareText:[NSString stringWithFormat:@"http://m.ibantang.com/topic/detail/%@", self.modleN.id]
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToRenren, UMShareToTencent,  nil]
                                       delegate:nil];
    
    
    
    
}


-(void)setModleN:(LzwModleNewTwo *)modleN{
    
    if (_modleN != modleN) {
        
        [_modleN release];
        
        _modleN = [modleN retain];
        
    }
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
